package com.xidian.zhiancloud.controller.chemicalsManagement.dangerousPart;

import com.alibaba.excel.EasyExcel;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.xidian.zhiancloud.constant.LedgerManagementConstant;
import com.xidian.zhiancloud.controller.base.BaseController;
import com.xidian.zhiancloud.dto.ResultDTO;
import com.xidian.zhiancloud.enums.GeneralResponseEnums;
import com.xidian.zhiancloud.exception.CustomizeException;
import com.xidian.zhiancloud.model.DangerousChemicalInventoryChangeRecord;
import com.xidian.zhiancloud.model.RelatedPartyBlacklist;
import com.xidian.zhiancloud.model.syset.SysUser;
import com.xidian.zhiancloud.qo.chemicalsManagement.DangerousChemicalIcrQO;
import com.xidian.zhiancloud.service.chemicalsManagement.chemicalManager.dangerousPart.DangerousChemicalInventoryChangeRecordService;
import com.xidian.zhiancloud.vo.chemicalsManagement.DangerousChemicalIcrVO;
import com.xidian.zhiancloud.vo.ledgerManagerment.relatedParty.RelatedPartyBlackListVO;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.net.URLEncoder;
import java.util.Arrays;
import java.util.Date;
import java.util.LinkedList;
import java.util.List;

/**
 * 危化品入库记录台账
 *
 * @Author: Egoist
 * @Date: 2020/11/10 17:31
 */
@RestController
@RequestMapping("/DangerousChemicalInventoryChangeRecord")
public class DangerousChemicalInventoryChangeRecordController extends BaseController {

    @Autowired
    private DangerousChemicalInventoryChangeRecordService dangerousChemicalInventoryChangeRecordService;

    @Transactional(rollbackFor = {RuntimeException.class, Error.class, CustomizeException.class})
    @PostMapping("/add")
    public ResultDTO<Boolean> add(DangerousChemicalInventoryChangeRecord dangerousChemicalInventoryChangeRecord){

        dangerousChemicalInventoryChangeRecord.setCompanyId(getSessionUserCompanyId());
        dangerousChemicalInventoryChangeRecord.setStoragePersonId(getSessionUserid());
        dangerousChemicalInventoryChangeRecord.setStorageTime(new Date(System.currentTimeMillis()));

        return ResultDTO.successOf(dangerousChemicalInventoryChangeRecordService.add(dangerousChemicalInventoryChangeRecord),
                GeneralResponseEnums.SUCCESS);
    }

    /**
     * 列表查询
     *
     * @param dangerousChemicalIcrQO 请求参数
     * @return 返回危化品入库台账记录
     */
    @GetMapping("/getListByQO")
    public ResultDTO<IPage<DangerousChemicalIcrVO>> getListByQueryObject(DangerousChemicalIcrQO dangerousChemicalIcrQO) {
        if (dangerousChemicalIcrQO.getCurrent() == null || dangerousChemicalIcrQO.getSize() == null) {
            return ResultDTO.errorOf(GeneralResponseEnums.REQUEST_ERROR);
        }
        dangerousChemicalIcrQO.setCompanyId(getSessionUserCompanyId());
        return ResultDTO.successOf(dangerousChemicalInventoryChangeRecordService.getListByQO(dangerousChemicalIcrQO), GeneralResponseEnums.SUCCESS);
    }

    /**
     * 导出
     */
    @GetMapping("/export")
    public void export(HttpServletResponse response, Long[] ids) throws IOException {
        ResultDTO.successOf(dangerousChemicalInventoryChangeRecordService.export(response, ids), GeneralResponseEnums.SUCCESS);
    }


}
